// GENERATE A RANDOM BANNER IMAGE

if (eval(unescape(window.location).match(/tsunami/i))) {
  // test if URL contains "tsunami"
  var n = 1; // default image
  var r = 4; // # of images in set
  n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
  i = "http://www.undp.org/images/intranet/banner/tsunami_" + n + ".jpg";
  credit = "";
}
else if ( eval(unescape(window.location).match(/jobs\.undp\.org/i)) || eval(unescape(window.location).match(/jobs-beta\.undp\.org/i)) )  {
  // test if URL contains "jobs.undp.org"
  var n = 1; // default image
  var r = 15; // # of images in set
  n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
  i = "http://www.undp.org/images/jobs/jobs_" + n + ".jpg";
  credit = "";

}
else if ( eval(unescape(window.location).match(/bulletin\.undp\.org/i)))  {
  // test if URL contains "bulletin.undp.org"
  var n = 1; // default image
  var r = 5; // # of images in set
  n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
  i = "http://www.undp.org/images/bulletin/bulletin_" + n + ".jpg";
  credit = "";
}
else {
  // no match, choose from one of the default sets
  var n = 1; // default image

  // pick a number between 1 and 10
  var chance = Math.round(Math.random()*9) + 1;

  // use each set 40/60% of the time
  if (chance > 6) {
    // UNCDF
    var r = 18; // # of images in set
    n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
    i = "http://www.undp.org/images/intranet/banner/uncdf_" + n + ".jpg";
    credit = "Banner photo by<br><a href=\"http://photos.uncdf.org/\" target=\"_blank\">Adam Rogers / UNCDF</a>.";
  } else {
    // Aerial Images
    var r = 27; // # of images in set
    n = (Math.round(Math.random()*(r - 1)) + 1); // generate random number
    i = "http://www.undp.org/images/intranet/banner/aerial_" + n + ".jpg";
    credit = "";
  }

}

// write image CSS
document.write('<style type="text/css">.banner {background-image: url(' + i + ');}</style>');

